#include"common.h"
int main(int argc, char **argv)
{
    int fd = -1, ret = 0;
    if(argc != 3) {
        level_print(ERR, "usage: %s <server-address> <file-name>", argv[0]);
        return FAILURE;
    }
    server_ip = strdup(argv[1]);
    if((ret = rdma_init()) != SUCCESS) {
        level_print(ERR, "rdma_init failed");
        return ret;
    }
    if((ret = get_file_info(argv)) != SUCCESS) {
        level_print(ERR, "get_file_info failed");
        goto rdma_destroy;
    }
    if((ret = client_socket_init(&fd)) != SUCCESS) {
        level_print(ERR, "client_socket_init failed");
        goto rdma_destroy;
    }
    if((ret = get_server_qp_mr_info(fd)) != SUCCESS) {
        level_print(ERR, "get_server_qp_mr_info failed");
        goto rdma_destroy;
    }
    if((ret = qp_state_modify()) != SUCCESS) {
        level_print(ERR, "qp_state_modify failed");
        goto rdma_destroy;
    }
    if((ret = client_work(fd)) != SUCCESS) {
        level_print(ERR, "client_work failed");
        goto rdma_destroy;
    }
rdma_destroy:
    close(fd);
    rdma_destroy();
    return ret;
}